package drp.snowbell.module;

import java.util.Collection;
import java.util.Map;

import drp.snowbell.cache.CacheSystem;
import drp.snowbell.cache.ICache;
import drp.snowbell.cfg.PartConfig;
import drp.snowbell.cfg.PropertyConfig;
import drp.snowbell.entity.IPart;
import drp.snowbell.entity.Property;


/**
 * 部件信息
 * 
 * @author wuhj
 * 
 */
public class PartInfo {
	private final String name;
	private final ICache<String, Property> propertyCache = CacheSystem.getCache(PartInfo.class.getName());
	private final Class<? extends IPart> partClass;
	private final Map<String, String> params;

	public PartInfo(Class<? extends IPart> partClass, PartConfig config, Map<String, String> params) {

		this.name = config.getName();
		for (PropertyConfig pc : config.getProperties()) {
			Property prop = new Property(partClass, pc, null, this.name);
			propertyCache.put(prop.getName(), prop);
		}
		this.params = params;
		this.partClass = partClass;
	}

	// 部件名称
	public String getName() {
		return name;
	}

	public Collection<String> getPropertyNames() {
		return propertyCache.keys();
	}

	public Property getProperty(String propertyName) {
		Property ret = propertyCache.get(propertyName);
		return ret;
	}

	public Class<? extends IPart> getPartClass() {
		return partClass;
	}

	public Map<String, String> getParams() {
		return params;
	}

}
